<template>
  <div class="fullscreen-container">
    <div class="content-wrapper">
      <el-card style="width: 100%;">
      <template #header>
        <div class="card-header">
          <span>当前考试</span>
        </div>
      </template>
      <div class="search-bar">
        <el-input v-model="searchQuery" placeholder="请输入考试名称" prefix-icon="Search" style="width: 400px;" />
        <el-button type="primary" @click="handleSearch">搜索</el-button>
      </div>
      <el-table :data="examsData" style="width: 100%">
        <el-table-column prop="examId" label="考试ID" width="80"></el-table-column>
        <el-table-column prop="examName" label="考试名称"></el-table-column>
        <el-table-column prop="courseName" label="所属课程" width="120"></el-table-column>
        <el-table-column prop="totalScore" label="总分" width="80"></el-table-column>
        <el-table-column prop="duration" label="考试时长(分钟)" width="150"></el-table-column>
        <el-table-column prop="startTime" label="开始时间" width="180"></el-table-column>
        <el-table-column prop="endTime" label="结束时间" width="180"></el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template #default="{ row }">
            <el-tag v-if="row.status === '未开始'" type="info">未开始</el-tag>
            <el-tag v-else-if="row.status === '进行中'" type="success">进行中</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template #default="{ row }">
            <el-button v-if="row.status === '进行中'" type="primary" size="small" @click="handleTakeExam(row)">进入考试</el-button>
            <el-button v-else type="info" size="small" disabled>未开始</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Search } from '@element-plus/icons-vue'

const router = useRouter()

// 模拟当前考试数据
const examsData = ref([
  { examId: 1, examName: '高等数学期中考试', courseName: '高等数学', totalScore: 100, duration: 90, startTime: '2024-10-20 09:00:00', endTime: '2024-10-20 10:30:00', status: '进行中' },
  { examId: 2, examName: '线性代数单元测试', courseName: '线性代数', totalScore: 50, duration: 60, startTime: '2024-10-22 14:00:00', endTime: '2024-10-22 15:00:00', status: '未开始' }
])

const searchQuery = ref('')
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(examsData.value.length)

const handleTakeExam = (row: any) => {
  // 进入考试
  ElMessage.info(`进入考试：${row.examName}`)
  // 这里可以跳转到考试答题页面
  // router.push(`/student/exam/take/${row.examId}`)
}

const handleSearch = () => {
  // 搜索功能
  ElMessage.info(`搜索：${searchQuery.value}`)
}

const handleSizeChange = (size: number) => {
  pageSize.value = size
}

const handleCurrentChange = (current: number) => {
  currentPage.value = current
}
</script>

<style scoped>
.fullscreen-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  background-color: #f5f5f5;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  overflow: hidden;
}

.content-wrapper {
  width: 100%;
  height: 100%;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.card-header {
  font-size: 18px;
  font-weight: bold;
}

.search-bar {
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>